package com.muyu.danmo.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoUaweFollow;
import com.muyu.danmo.req.DanmoFollowUserListReq;
import com.muyu.danmo.req.DanmoUaweFollowReq;
import com.muyu.danmo.service.IDanmoUaweFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 用户关注Controller
 *
 * @author yangle
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/follow")
public class DanmoUaweFollowController extends BaseController
{
    @Autowired
    private IDanmoUaweFollowService danmoUaweFollowService;

    /**
     * 查询用户关注列表
     */
//    @RequiresPermissions("system:follow:list")
    @GetMapping("/list")
    public Result list(DanmoUaweFollow danmoUaweFollow)
    {
        PageHelper.startPage(danmoUaweFollow.getPageNum(),danmoUaweFollow.getPageSize());

        List<DanmoUaweFollow> list = danmoUaweFollowService.selectDanmoUaweFollowList(danmoUaweFollow);
        PageInfo<DanmoUaweFollow> danmoInformationPageInfo = new PageInfo<>(list);

        return Result.success(danmoInformationPageInfo);
    }

    /**
     * 导出用户关注列表
     */
//    @RequiresPermissions("system:follow:export")
    @Log(title = "用户关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoUaweFollow danmoUaweFollow)
    {
        List<DanmoUaweFollow> list = danmoUaweFollowService.selectDanmoUaweFollowList(danmoUaweFollow);
        ExcelUtil<DanmoUaweFollow> util = new ExcelUtil<DanmoUaweFollow>(DanmoUaweFollow.class);
        util.exportExcel(response, list, "用户关注数据");
    }

    /**
     * 获取用户关注详细信息
     */
//    @RequiresPermissions("system:follow:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoUaweFollowService.selectDanmoUaweFollowById(id));
    }

    /**
     * 新增用户关注
     */
//    @RequiresPermissions("system:follow:add")
    @Log(title = "用户关注", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoUaweFollow danmoUaweFollow)
    {
        return toAjax(danmoUaweFollowService.insertDanmoUaweFollow(danmoUaweFollow));
    }

    /**
     * 修改用户关注
     */
//    @RequiresPermissions("system:follow:edit")
    @Log(title = "用户关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoUaweFollow danmoUaweFollow)
    {
        return toAjax(danmoUaweFollowService.updateDanmoUaweFollow(danmoUaweFollow));
    }

    /**
     * 删除用户关注
     */
//    @RequiresPermissions("system:follow:remove")
    @Log(title = "用户关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoUaweFollowService.deleteDanmoUaweFollowByIds(ids));
    }

    /**
     * 查询某个用户关注的所有用户
     */
    @PostMapping("/followUserList")
    public Result followUserList(@RequestBody DanmoFollowUserListReq danmoUaweFollowReq)
    {
       List<DanmoUaweFollow> list = danmoUaweFollowService.followUserList(danmoUaweFollowReq);
        return Result.success(list);
    }

    /**
     * 查询关注某个用户的所有用户：
     */
    @PostMapping("/concernUserList")
    public Result concernUserList(@RequestBody DanmoUaweFollowReq danmoUaweFollowReq)
    {
        List<DanmoUaweFollow> list = danmoUaweFollowService.concernUserList(danmoUaweFollowReq);
        return Result.success(list);
    }

    /**\
     * 添加用户A关注用户B
     */
    @PostMapping("/addFollow")
    public Result addFollow(@RequestBody DanmoUaweFollow danmoUaweFollow)
    {
        return danmoUaweFollowService.addFollow(danmoUaweFollow);
    }
    /**\
     * 用户A取消关注用户B：
     */
    @PostMapping("/delFollow")
    public Result delFollow(@RequestBody DanmoUaweFollow danmoUaweFollow)
    {
        return danmoUaweFollowService.delFollow(danmoUaweFollow);
    }
}
